package stu.wingsmaker.artofsubway.view;

import stu.wingsmaker.artofsubway.R;
import stu.wingsmaker.artofsubway.model.adapter.CulturePlaceListCursorAdapter;
import stu.wingsmaker.artofsubway.model.database.CultureDatabaseOpenHelper;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockFragment;

public class CultureListFragment extends SherlockFragment {
	private ListView cultureListview;
	private CulturePlaceListCursorAdapter dbAdapter;
	private CultureDatabaseOpenHelper dbHelper;
	private SQLiteDatabase sdb;
	private Cursor cursor;
	private String sql; 
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		dbHelper = new CultureDatabaseOpenHelper(getActivity(), getTag(), null, getId());
		//System.out.println("db create");
		View root = inflater.inflate(R.layout.culturelist_fragment, container, false);
		// TODO Auto-generated method stub
		cultureListview = (ListView) root.findViewById(R.id.cultureList);
		sdb = dbHelper.getReadableDatabase();
		sql = "SELECT * FROM "+ dbHelper.PLACETABLE +";";
		cursor = sdb.rawQuery(sql, null);
		if(cursor.getCount() > 0) {
			//startManagingCursor(cursor);
			dbAdapter = new CulturePlaceListCursorAdapter(getActivity(), cursor);
			cultureListview.setAdapter(dbAdapter);
		}
		
		return root;
	}
}
